﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Box2D.XNA;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input.Touch;
using Microsoft.Devices.Sensors;

namespace Elementum
{
    public class StateFactory
    {
        static public GroundObject CreateGround(Stage stage, int x, int y, int width, int height, float rotation)
        {
            GroundObject grount = new GroundObject(stage.World,stage);
            grount.Position = new Vector2(x, y);
            grount.CurrentAnimation = new Animation("images/system/black", new Point(width, height));
            grount.Size = new Vector2(width, height);
            grount.Rotation = rotation;
            stage.Actors.Add(grount);
            return grount;
        }

        static public GroundObject CreatekillBund(Stage stage, int x, int y, int width, int height, float rotation)
        {
            GroundObject underBund = new GroundObject(stage.World, stage);
            underBund.Position = new Vector2(x, y);
            underBund.CurrentAnimation = new Animation("images/ground/kill", new Point(width, height));
            underBund.Size = new Vector2(width, height);
            underBund.BodyData = "killBund";
            underBund.Rotation = rotation;
            stage.Actors.Add(underBund);
            return underBund;
        }

        static public ElementPiece CreateElementPiece(String pieceId,Stage stage, int x, int y)
        {
            ElementPiece element = new ElementPiece(pieceId, stage.World, stage);
            element.Position = new Vector2(x, y);
            stage.Actors.Add(element);
            return element;
        }

        static public SpotLight CreateSpotLight(Stage stage, int x, int y, int range, int scanRange, int baseAngle)
        {
            SpotLight _spotLight = new SpotLight(stage.Game, stage.World);
            _spotLight.Position = new Vector2(x, y);
            _spotLight.Range = range;
            _spotLight.ScanRange = scanRange;
            _spotLight.BaseAngle = baseAngle;//-165~-75
            //_spotLight.AddToList(_spotLight);
            return _spotLight;
        }

        static public ProtalGate CreatePortal(String PortalId, Stage stage, int x, int y, String stageId, String desPortalId)
        {
            ProtalGate protalSwitch = new ProtalGate(PortalId, stage.World, stage);
            protalSwitch.ProtalCommand = new ProtalCommand(stageId, desPortalId);
            protalSwitch.Position = new Vector2(x, y);
            stage.Actors.Add(protalSwitch);
            return protalSwitch;
        }

        //gameSwitch.AddTarget("");
        static public Switch CreateSwitch(Stage stage, int x, int y)
        {
            Switch gameSwitch = new Switch(stage.World, stage);
            gameSwitch.Position = new Vector2(x, y);
            gameSwitch.Size = new Vector2(50, 50);
            stage.Actors.Add(gameSwitch);
            return gameSwitch;
        }

        //sensorSwitch.AddTarget("");
        static public SensorSwitch CreateSensorSwitch(Stage stage, int x, int y)
        {
            SensorSwitch sensorSwitch = new SensorSwitch(stage.World, stage);
            sensorSwitch.Position = new Vector2(x, y);
            sensorSwitch.Size = new Vector2(50, 10);/////
            stage.Actors.Add(sensorSwitch);
            return sensorSwitch;
        }

        static public GameDoor CreateDoor(String DoorId,Stage stage, int x, int y,String IdForKey)
        {
            GameDoor door = new GameDoor(DoorId, stage.World, stage);
            door.Position = new Vector2(x, y); 
            door.Size = new Vector2(60, 100);
            door.DoorID = IdForKey;
            stage.Actors.Add(door);
            return door;
        }

        static public GameKey CreateKey(String KeyId, Stage stage, int x, int y, String IdForOpenDoor)
        {
            GameKey key = new GameKey(KeyId, stage.World, stage);
            key.Position = new Vector2(x, y); 
            key.Size = new Vector2(23, 35);
            key.KeyID = IdForOpenDoor;
            stage.Actors.Add(key);
            return key;
        }

        //mechine.AddTarget("");
        static public Mechine CreateMechine(String MechineId, Stage stage,int x,int y,int capacity)
        {
            Mechine mechine = new Mechine(MechineId, stage.World, stage);
            mechine.Position = new Vector2(x, y);
            mechine.Capacity = capacity;
            stage.Actors.Add(mechine);
            return mechine;
        }

        static public MechanismGound CreateMechanismGound(Stage stage, int x, int y, int width, int height, float rotation, int changeX, int changeY, int startTime, int endTime)
        {
            MechanismGound mechanismGound = new MechanismGound(stage.World, stage);
            mechanismGound.Position = new Vector2(x, y);
            mechanismGound.CurrentAnimation = new Animation("images/ground/labwall", new Point(width, height));
            mechanismGound.Size = new Vector2(width, height);
            mechanismGound.Rotation = rotation;
            stage.Actors.Add(mechanismGound);

            ModifierContain first = new ModifierContain(mechanismGound);
            ModifierContain next = new ModifierContain(mechanismGound);
            //設定機關行為
            PositionModifier m2 = new PositionModifier(mechanismGound.Position, mechanismGound.Position + new Vector2(changeX, changeY), startTime, endTime);
            PositionModifier m3 = new PositionModifier(mechanismGound.Position + new Vector2(changeX, changeY), mechanismGound.Position, startTime, endTime);
            first.AddModifier(m2);
            next.AddModifier(m3);

            mechanismGound.PositiveAction.Add(first);// = first;
            mechanismGound.NegetiveAction.Add(next); // = next;

            return mechanismGound;
        }

        static public Floor CreateFloor(Stage stage, int x, int y, int width, int height, float rotation, int changeX, int changeY, int startTime, int endTime)
        {
            Floor floor = new Floor(stage.World, stage);
            floor.Position = new Vector2(x, y);
            floor.CurrentAnimation = new Animation("images/items/floor", new Point(width, height));
            floor.Size = new Vector2(width, height);
            floor.Rotation = rotation;
            stage.Actors.Add(floor);

            ModifierContain first = new ModifierContain(floor);
            ModifierContain next = new ModifierContain(floor);
            //設定機關行為
            PositionModifier m2 = new PositionModifier(floor.Position, floor.Position + new Vector2(changeX, changeY), startTime, endTime);
            PositionModifier m3 = new PositionModifier(floor.Position + new Vector2(changeX, changeY), floor.Position, startTime, endTime);
            first.AddModifier(m2);
            next.AddModifier(m3);

            floor.PositiveAction.Add(first);// = first;
            floor.NegetiveAction.Add(next);// = next;

            return floor;
        }

    }
}
